package com.edz.from0507to0513apk.View;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.edz.from0507to0513apk.Base.BaseActivity;
import com.edz.from0507to0513apk.Base.Config;
import com.edz.from0507to0513apk.Entity.GasModel;
import com.edz.from0507to0513apk.R;
import com.edz.from0507to0513apk.Util.NetUtils;
import com.google.gson.Gson;
import com.google.zxing.WriterException;

import java.io.IOException;

import butterknife.BindView;
import okhttp3.Call;
import okhttp3.Response;

/**
 * 预约加油，生成二维码订单
 */
public class GasolineActivity extends BaseActivity {

    @BindView(R.id.tv_data)
    TextView tv_data;
    @BindView(R.id.btn_createcode)
    Button btn_createcode;
    @BindView(R.id.iv_code)
    ImageView iv_code;

    private String str_code = null;

    private static final String TAG = GasolineActivity.class.getSimpleName();

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_gasoline;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        NetUtils.getInstance().getDataAsynFromNet(Config.str_url_juhe_gas, new NetUtils.MyNetCall() {
            @Override
            public void success(Call call, Response response) throws IOException {
                final String str_res = response.body().string();
                Gson gson = new Gson();
                final GasModel gasModel = gson.fromJson(str_res, GasModel.class);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (gasModel.getResultcode().equals("200")) {
                            str_code = "E90号汽油单价：" + gasModel.getResult().getData().get(0).getPrice().getE90() + "元/L"
                                    + "\n加油站地址：" + gasModel.getResult().getData().get(0).getAddress();
                            tv_data.setText(str_code);
                        }
                    }
                });
            }

            @Override
            public void failed(Call call, IOException e) {

            }
        });
    }

    @Override
    protected void setEvent() {
        btn_createcode.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
    }

}
